// pages/home/store/coloruiIndex.js
const app = getApp();
const http = require('../../../utils/http.js')
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },
  options: {
    addGlobalClass: true,
  },
  lifetimes: {
    attached: function() {
      // 在组件实例进入页面节点树时执行
      var that=this
      this.setData({
          customer: app.globalData.customer
      })
      //  高度自适应
      wx.getSystemInfo({
        success: function (res) {
          var clientHeight = res.windowHeight-115,
            clientWidth = res.windowWidth,
            rpxR = 750 / clientWidth;
          var calc = clientHeight * rpxR;
          //console.log(calc)
          that.setData({
            winHeight: calc
          });
        }
      });
      this.setData({
        customer: app.globalData.customer
      })
      this.interfaceCall();
    }
  },
  pageLifetimes: {
    show: function() {
      // 页面被展示
      this.interfaceCall();
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    typeZt:null,
    customer:null,
    typelx:0,
    navUl:null,
    navList:null,
    txtString:null
  },

  /**
   * 组件的方法列表
   */
  methods: {
    lx:function(e){
      var lx1=''
      var lx2=''
      if(e.currentTarget.dataset.state==0){
        this.setData({
          typelx:e.currentTarget.dataset.state,
          typeZt:this.data.type.floor[0].name
        })
      }
      if(e.currentTarget.dataset.state==1){
        this.setData({
          typelx:e.currentTarget.dataset.state,
          typeZt:this.data.type.brand[0].name
        })
      }
      if(this.data.typelx==0){
        lx1=this.data.type.floor[0].id
      }else{
        lx2=this.data.type.brand[0].id
      }
      http.get('/api/brand/selectStore2',{floorType:lx1,brandType:lx2}).then(res => {
        //console.log(res)
        if(!res.data.length){
          wx.showToast({
            title:'暂无数据',
            icon:'none'
          })
        }
        if (res.code == 200 && res.data) {
          this.setData({
            list:res.data
          })
        }
      })
    },
    stateBtn:function(e){
      var that = this
      var lx1=''
      var lx2=''
      that.setData({
        typeZt: e.currentTarget.dataset.name
      })
      if(this.data.typelx==0){
        lx1=e.currentTarget.dataset.state
      }else{
        lx2=e.currentTarget.dataset.state
      }
      http.get('/api/brand/selectStore2',{floorType:lx1,brandType:lx2}).then(res => {
        //console.log(res)
        if(!res.data.length){
          wx.showToast({
            title:'暂无数据',
            icon:'none'
          })
        }
        if (res.code == 200 && res.data) {
          this.setData({
            list:res.data
          })
        }
      })
      //console.log(e.currentTarget.dataset.state)
      // http.get('/api/product/getProductList',{categoryId: e.currentTarget.dataset.state}).then(res => {
      //   if (res.code == 200 && res.result) {
      //     //console.log(res)
      //       this.setData({
      //           navList: res.result
      //       })
      //       //console.log(this.data.navList)
      //   }
      //   if(!res.result.length){
      //     wx.showToast({
      //       title:'暂无商品',
      //       icon:'none'
      //     })
      //   }
      // })
    },
    productDetailClick:function(e){
      wx.navigateTo({
        url: '/pages/home/store/index?id='+e.currentTarget.dataset.id,
      })
    },
    inputClick:function(e){
      //console.log('picker发送选择改变，携带值为', e.detail.value)
      this.setData({
        txtString: e.detail.value
      })
    },
    search:function(){
      if(this.data.txtString){
        wx.navigateTo({
          url: '/pages/home/storeList/index?txtString='+this.data.txtString,
        })
      }else{
        wx.showToast({
          title:'请输入要搜索的店铺',
          icon:'none'
        })
      }
      
    },
    interfaceCall:function(){

      http.get('/api/brand/selectByDistType').then(res => {
        //console.log(res)
        if(res.data.length){
          wx.showToast({
            title:'请联系管理员后台添加数据',
            icon:'none'
          })
        }
        if (res.code == 200 && res.data) {
          this.setData({
            type:res.data,
            typeZt: res.data.floor[0].name,
            typelx:0
          })
          http.get('/api/brand/selectStore2',{floorType:res.data.floor[0].id}).then(res => {
            //console.log(res)
            if(!res.data.length){
              wx.showToast({
                title:'暂无数据',
                icon:'none'
              })
            }
            if (res.code == 200 && res.data) {
              this.setData({
                list:res.data
              })
            }
          })
        }
      })
    }
  }
})
